import axios from 'axios'

const getMisList = async (filter: string): Promise<Array<{ name: string, age: number }>> => {
    if (!filter) {
        return []
    }
    const res: [{ name: string, age: number }] = await axios.post('http://api', { filter });
    return res || [];
}

// 可选入参
const handleClose = (isShow?: boolean) => {
    if (isShow) {
        return 1
    }
    return '1'
}

enum TypeList {
    'zs' = 0,
    'ls' = 1,
    'ww' = 2
}

interface Mode {
    type: TypeList
}

// 解构入参
const handleOpen = ({ mode, id }: { mode: Mode; id?: number }) => {
    if (id) {
        return TypeList[0]
    }
    return TypeList['ls']
}

const msg = handleOpen({ mode: { type: 1 }, id: 1 })
console.log(msg);


function add(x: number, y: number) {
    return x + y;
}

const handleSearch = async (filter: string, page: { pageNo: number, pageSize: number }) => {
    const { pageNo, pageSize } = page;
    const data: {
        pageList: [{ [key: string]: any }],
        page: { totalCount: number },
    } = await axios.post('http://api', { filter, page });
    return {
        pageList: data?.pageList || [],
        page: {
            pageNo,
            pageSize,
            totalCount: data?.page?.totalCount,
        },
    };
}

const getDateList = async (filter?: string): Promise<Array<{ name: string, age: number }>> => {
    const res = await axios.get('http://localhost:8888/')
    const result: [{ name: string, age: number }] = (res as any).data
    return result || []
}

console.log(getDateList());


interface XIAOJIEJIE {
    name?: string;
    age?: number;
    type?: string;
    id?: number;
}

const getSearchParmas = (defaultValue: Record<keyof XIAOJIEJIE, any>) => {
    return defaultValue
}
getSearchParmas({name: 123, age: 'zs', type: 'zs', id: '111'})


export {
    getMisList,
    handleSearch
}
